package com.aaa.rabbitmq.two;

import com.aaa.rabbitmq.one.util.RabbitMQUtil;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 这是一个工作线程  相当于一个消费者
 */
public class Work01 {
    //队列名称
    public static final String QUEUE_NAME="hello";
    //接收消息
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMQUtil.getChannel();
        //声明接受消息
        DeliverCallback deliverCallback = (var1, var2) -> {
            System.out.println("work01工作线程消费消息"+new String(var2.getBody()));
        };
        //取消消息的
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println(consumerTag+"消息消费被中断");
        };
        //消费者接受/消费消息
        //1 消费队列，2消费成功是否自动应答，3，消费者未成功消费的回调 4,消费者取消消费的回调
        System.out.println("work002等待。。。。。。");
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);
    }

}
